﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BllService;
using DBModel;
using Utility;
using System.Runtime.Serialization.Json;
using System.Web.Security;
using System.IO;
public class BaseService : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
    #region =====IHttpHandler 接口处理=====
    int page = 0;
    int limit = 0;
    public void ProcessRequest(HttpContext context)
    {
        //string sessionid = context.Session.SessionID;
        //Utility.LogHelper.InstanctLogHelper.WriteLog("Session:" + context.Session.SessionID);

        context.Session.Timeout = 1;
        context.Response.ContentType = "text/plain";

        page = string.IsNullOrEmpty(context.Request["page"]) ? 0 : Convert.ToInt32(context.Request["page"]);
        limit = string.IsNullOrEmpty(context.Request["limit"]) ? 0 : Convert.ToInt32(context.Request["limit"]);
        string function = context.Request["model"].ToString();
        System.Reflection.MethodInfo method = typeof(BaseService).GetMethod(function);
        string res = "";
        if (method != null)
        {
            Object[] parametors = new Object[] { context };
            res = method.Invoke(this, parametors).ToString();
        }
        context.Response.Write(res);
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
    #endregion

    #region device_map
    public string getDevice(HttpContext context)
    {
        Map_Device model = Utility.HttpContextToEntity.HttpContextToModel<Map_Device>(context);
        SysBasicService server = new SysBasicService();
        return server.getDevice(model);
    }
    public string AddDevice(HttpContext context)
    {
        Map_Device model = Utility.HttpContextToEntity.HttpContextToModel<Map_Device>(context);
        SysBasicService server = new SysBasicService();
        return server.AddDevice(model);
    }
    public string getDeviceSelect(HttpContext context)
    {
        SysBasicService server = new SysBasicService();
        return server.getDeviceSelect();
    }
    #endregion
}
